package demo3;

/**
 * @Author 12629
 * @Description：
 */
public class Test {

    public static void drawMap(Shape shape) {
        shape.draw();
    }

    public static void main(String[] args) {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        Triangle triangle = new Triangle();

        /*
        Shape rect = new Rect();
        Shape cycle = new Cycle();
        Shape flower = new Flower();
        */
        Shape[] shapes = {rect,cycle,rect,cycle,flower,triangle};//向上转型

        for(Shape shape : shapes) {
            shape.draw();
        }

        /*for(int i = 0;i < shapes.length;i++) {
            Shape shape = shapes[i];
            shape.draw();
        }*/

       /* drawMap(rect);

        drawMap(cycle);

        drawMap(flower);

        drawMap(triangle);*/
    }



    public static void main2(String[] args) {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();

        String[] shapes = {"cycle", "rect", "cycle", "rect", "flower"};

        for (String shape : shapes) {
            if (shape.equals("cycle")) {
                cycle.draw();
            } else if (shape.equals("rect")) {
                rect.draw();
            } else if (shape.equals("flower")) {
                flower.draw();
            }
        }
    }



    public static void main1(String[] args) {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();


        drawMap(rect);

        drawMap(cycle);

        drawMap(flower);


    }
}
